import 'package:flutter/material.dart';
import 'package:fluttermodule/customerDetail/customer_detail_view_model.dart';
import 'package:fluttermodule/customerDetail/customer_detail_model.dart';
import '../service/service_method.dart';

class CustomerDetailProvide with ChangeNotifier {
  List<CustomerDetailViewModel> listData = [];

  //获取客户详情
  getCustomerDetail() async {
    await request('getCustomerDetail').then((val) {
      var customerDetailModel = CustomerDetailModel.fromJson(val);
      listData.clear();
      listData.add(CustomerDetailViewModel(CustomerDetailViewModel.TYPE_HEADER,
          customerDetailHeader: customerDetailModel.customerDetailHeader));
      var content = customerDetailModel.customerDetailContent;
      if (content != null && content.isNotEmpty) {
        for (int i = 0; i < content.length; i++) {
          CustomerDetailContent customerDetailContent = content[i];
          customerDetailContent.isLast = i == content.length - 1;
          listData.add(CustomerDetailViewModel(
              CustomerDetailViewModel.TYPE_CONTENT,
              customerDetailContent: customerDetailContent));
        }
      }
      listData.add(CustomerDetailViewModel(CustomerDetailViewModel.TYPE_FOOTER,
          customerDetailFooter: customerDetailModel.customerDetailFooter));
      notifyListeners();
    });
  }
}
